#ifndef __CITY__
#define __CITY__
#include <vector>
#include <set>
#include <iostream>
#include "cell.h"
#include "loan.h"
#include "building.h"

using namespace std;

class cursor{
	public:
		cursor(int x, int y, int limit_y, int limit_x): x(x), y(y),
			limit_x(limit_x), limit_y(limit_y){}

		void up();
		void down();
		void left();
		void right();
		int posx() const;
		int posy() const;
		int limitx() const;
		int limity() const;

	private:
		int x, y, limit_x, limit_y;
};

class city{

	public:
		vector<building> get_buildings(){ return _buildings; }
		vector<vector<cell>> get_map(){ return _map; }
		int get_money(){ return _money; }
		int get_time(){ return _time; }
		string get_name(){ return _name; }
		cursor& get_cursor(){ return _select; }
		int get_population(){ return _population; }
		int get_residentials(){ return _residentials; }
		int get_shops(){ return _shops; }
		int get_industry(){ return _industry; }

		int get_needed_shops();
		int get_needed_residentials();
		int get_needed_industry();

		cell get_cell(){ return _map[_select.posx()][_select.posy()]; }
		int get_size(){ return _size; }

		void set_map(vector<vector<cell>> map){ _map = map; }
		void set_money(int money){ _money = money; }
		void set_time(int time){ _time = time; }
		void set_name(const string& name){ _name = name; }
		void set_cursor(cursor select){ _select = select; }
		void set_population(int population){ _population = population; }
		void set_residentials(int residentials){ _residentials = residentials; }
		void set_shops(int shops){ _shops = shops; }
		void set_industry(int industry){ _industry = industry; }
		void set_cell(cell c);
		void set_pipe();
		void set_waste(int waste){ _waste = waste; }
		void flow_water(int i, int e);
		city(const string& name, int money, int size = BUILDING_TYPES_SIZE);
		void print();

		void cursor_up(){ _select.up(); }
		void cursor_down(){ _select.down(); }
		void cursor_left(){ _select.left(); }
		void cursor_right(){ _select.right(); }
 		void nextGeneration();

		int road(int i, int e);
		int population(int i, int e);
		int income();
		void electricity(int i, int e);
		void water(int i, int e);
		void ecosystem_pollution(vector<vector<cell>>& new_field, int i, int e);
		void insertion_not_repeated(cursor c, vector<cursor>& v);
		void save();
		void load();
		void create();
		vector<pair<int,int>> dijkstra(int x, int y);
		vector<pair<int,int>> smaller_route(int origin_x, int origin_y, int destination_x, int destination_y);
		vector<pair<int,int>> dijkstra(int x, int y, int dest_x, int dest_y);
		pair<int,int> get_near_road(int i, int e);
		void road_traffic(int i, int e);
		void unemploy_cell(int x, int y);
		void employ_cell(int x, int y);
		void get_loan();
		int positions_to_node(int i, int e);
		pair<int,int> node_to_positions(int node);
		void pay_bigger_city();
	private:
		vector<vector<cell>> _map;
		vector<building> _buildings;
		vector<pair<int,int>> _unemployment_vector;

		vector<loan> _possible_loans;
		vector<loan> _asked_out_loans;

		string _name;
		
		int _size;
		int _money;
		int _time;
		int _population;
		int _residentials;
		int _shops;
		int _industry;
		int _waste;
		int _wind;

		cursor _select;
};
#endif
